home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_13_01 / allison / searches.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-02  |  859 b   |  43 lines

  1. LISTING 13 - Illustrates selected string search functions
  2.  
  3. #include <stdio.h>
  4. #include <string.h>
  5.  
  6. void display_span(char *, int);
  7.  
  8. main()
  9. {
  10.     char *s = "Eeek! A mouse device!";
  11.     char *vowels = "AEIOUaeiou";
  12.     char *punct = "`~!@#$%^&*()-_=+\\|[{]};:'\",<.>/?";
  13.     char *ptr;
  14.  
  15.     display_span(s,strspn(s,vowels));
  16.     display_span(s,strspn(s,punct));
  17.     display_span(s,strcspn(s,vowels));
  18.     display_span(s,strcspn(s,punct));
  19.  
  20.     ptr = strpbrk(s,vowels);
  21.     puts(ptr);
  22.  
  23.     ptr = strpbrk(s,punct);
  24.     puts(ptr);
  25.  
  26.     return 0;
  27. }
  28.  
  29. void display_span(char *s, size_t index)
  30. {
  31.     printf("%d characters spanned: %.*s\n",
  32.             index,index,s);
  33. }
  34.  
  35. /* Output: */
  36. 3 characters spanned: Eee
  37. 0 characters spanned: 
  38. 0 characters spanned: 
  39. 4 characters spanned: Eeek
  40. Eeek! A mouse device!
  41. ! A mouse device!
  42.  
  43.